<template>
	<view class="job-box">
		<view class="hd fboxRow Ycenter font34" @click="goPage">
			<view class="fboxCol flex1">
				<view class="title lh44">{{innerData.realName}}</view>
				<view class="info color-ACB4C7 font26 lh40">
					<text>{{innerData.resumeIdentity == 2 ? '在校/应届生': innerData.workYears}}</text>
					<text style="margin: 0 10rpx;">{{gainData(innerData.education, 'educationList').label}}</text>
					<text v-if="innerData.salaryMin == 0 || !innerData.salaryMin">面议</text>
					<text v-else>{{unitNum(innerData.salaryMin)}}-{{unitNum(innerData.salaryMax)}}</text>
				</view>
			</view>
			<view class="user fboxRow Ycenter">
				<view class="fboxCol Yend" v-if="innerData.matchIndex">
					<view class="fboxRow Ycenter mt10">
						<RateItem :num="innerData.matchIndex" size="font24" />
					</view>
					<view class="font22 mt10 color-6B707C">匹配指数</view>
				</view>
				<image class="avatar" :src="innerData.avatar" mode="aspectFill"></image>
			</view>
		</view>
		<view class="bd" @click="goPage">
			<view class="fboxRow Ycenter font26 lh38" v-if="type=='invitationRecord'">
				<text class="font-ell1">邀约职位：{{innerData.jobName}}</text>
			</view>
			<view class="fboxRow Ycenter font26 lh38" v-else-if="type=='resumeReceived'">
				<text class="font-ell1">所投职位：{{innerData.jobName}}</text>
			</view>
			<view class="fboxRow Ycenter font26 lh38" v-else>
				<!-- <u-icon name="heart-fill" color="#ACB4C7"></u-icon> -->
				<image class="icon" src="https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-5.png" mode="aspectFill"></image>
				<text class="font-ell1" style="margin-left: 12rpx;">期望职位：{{String(innerData.expectPositionList)}}</text>
			</view>
			<view class="tags fboxWrap mt16" v-if="innerData.resumeKeywordList">
				<view class="tag font-ell1 fboxRow Ycenter Xcenter font26"
					v-for="(item,index) in innerData.resumeKeywordList" :key="index">{{item}}</view>
			</view>
			<view class="fboxRow Ycenter mt24 lh40  font28 font-ell2 color-ACB4C7">{{innerData.advantage}}</view>
		</view>
		<view class="ft fboxRow Ycenter Xend">
			<view class="flex1">
				<text class="font26 lh38 color-6B707C"
					v-if="type=='deliverPage'">邀约时间：{{innerData.gmtSend.slice(0, 10)}}</text>
				<text class="font26 lh38 color-ACB4C7"
					v-if="type=='invitationRecord'">面试时间：{{getNowDate(innerData.gmtInterview)}}</text>
				<text class="font26 lh38 color-6B707C"
					v-if="type=='resumeReceived' || type=='collectedResume'">{{innerData.gmtCreate.slice(0, 16)}}</text>
			</view>
			<view class="btn-group fboxRow">
				<template v-if="type != 'invitationRecord'">
					<view v-if="type == 'talent' && !_innerData.inviteFlag || !_innerData.isInvited && type != 'talent'" class="btn btn-border fboxRow Ycenter Xcenter color-E8CDA7 font26" @click="invited">
						邀约面试
					</view>
				<!-- 	<view v-else-if="!_innerData.isInvited && type != 'talent'" class="btn fboxRow Ycenter Xcenter btn-border color-E8CDA7 font26" @click="invited">
						邀约面试
					</view> -->
					<view v-else class="btn fboxRow Ycenter Xcenter btn-bg font26">已邀约</view>
				</template>
				<view class="btn fboxRow Ycenter Xcenter bg-linear color-141720 font26" @click="contact">沟通一下</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		gainData
	} from '../common/config.js';
	import {
		unitNum
	} from '@/static/js/common.js';
	import RateItem from '../components/rate-item.vue';
	import {
		timestampToTime,
		getDate
	} from '@/static/js/common.js';
	import {
		jobCommunicate
	} from '@/api/recruit.js';
	export default {
		components: {
			RateItem
		},
		props: {
			type: {
				type: String,
				default: '' // resumeReceived 收到的简历 | invitationRecord邀约记录 | collectPage职位收藏
			},
			innerData: {
				type: Object,
				default: () => {
					return {}
				}
			},
			jobId: {
				type: [String, Number],
				default: ''
			},
		},
		data() {
			return {
				gainData,
				unitNum,
				isInvite: false

			}
		},
		computed: {
			_innerData: {
				get() {
					return this.innerData
				},
				set(val) {
					this.$emit('update:innerData', val)
				}
			}
		},
		methods: {
			goPage() {
				const companyId = getApp().globalData.companyId
				const jobId = this.jobId || this.innerData.jobId
				const id = this.innerData.resumeId || this.innerData.id
				let params = ''
				if (jobId) {
					params = `&id=${id}&companyId=${companyId}&jobId=${jobId}`
				} else {
					params = `&id=${id}&companyId=${companyId}`
				}

				this.$pageTo(`/recruit/user/detail?pageType=2${params}`)

			},
			getNowDate(d) {
				let date = new Date(d);
				let sign2 = ":";
				let year = date.getFullYear() // 年
				let month = date.getMonth() + 1; // 月
				let day = date.getDate(); // 日 
				let hour = date.getHours(); // 时
				let minutes = date.getMinutes(); // 分
				let seconds = date.getSeconds() //秒
				let weekArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
				let week = weekArr[date.getDay()]; //getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)
				let noon = '上午'
				// 给一位数的数据前面加 “0”
				// if (month >= 1 && month <= 9) {
				//     month = "0" + month;
				// }
				// if (day >= 0 && day <= 9) {
				//     day = "0" + day;
				// }
				if (hour >= 0 && hour <= 9) {
					hour = "0" + hour;
				}
				if (minutes >= 0 && minutes <= 9) {
					minutes = "0" + minutes;
				}
				if (seconds >= 0 && seconds <= 9) {
					seconds = "0" + seconds;
				}
				if (hour > 12) {
					noon = '下午'
				}
				const edate = month + "月" + day + '日（' + week + '）' + noon + ' ' + hour + sign2 + minutes
				return edate
			},
			contact() {
				if(getApp().globalData.companyInfo.authStatus != 1){
					uni.showToast({
						icon: 'none',
						title: '你的企业还未认证，请先认证后再操作！'
					})
					return
				}
				console.log(this.innerData)
				const data = {
					type: 'contact',
					memberId: this.innerData.memberId,
					userName: this.innerData.realName
				}
				console.log(data)
				jobCommunicate({
					id: this.jobId
				}).then(res => {})
				this.$bridge.callHandler('recruitHandler', data, () => {
					console.log('recruitHandler', '返回')
				})
			},
			invited() {
				console.log(this.innerData)
				if(getApp().globalData.companyInfo.authStatus != 1){
					uni.showToast({
						icon: 'none',
						title: '你的企业还未认证，请先认证后再操作！'
					})
					return
				}
				this.isInvite = true
				const id = this.innerData.resumeId || this.innerData.id
				const jobId = this.jobId || this.innerData.jobId
				this.$pageTo('/recruit/enterprise/invitation?id=' + id+ '&jobId=' + jobId + '&companyId=' + getApp().globalData
					.companyId)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.job-box {
		margin-bottom: 24rpx;
		padding: 32rpx 24rpx 24rpx;
		// width: 670rpx;
		border-radius: 12rpx;
		background-color: var(--viewBgColor);
	}

	.job-box .bd {
		margin-top: 30rpx;
	}


	.job-box .tags .tag {
		padding: 0 12rpx;
		margin: 24rpx 24rpx 0 0;
		max-width: 200rpx;
		height: 46rpx;
		line-height: 46rpx;
		background: #F4F8FB;
		color:var(--contentFontFourColor);
		border-radius: 23rpx;
	}

	.job-box .tags .tag:last-child {
		margin-right: 0;
	}

	.job-box .name {
		margin-right: 30rpx;
		height: 38rpx;line-height: 38rpx;
	}

	.job-box .info {
		margin-top: 22rpx;
	}

	.job-box .avatar {
		margin-left: 16rpx;
		width: 88rpx;
		height: 88rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	.job-box .address {
		line-height: 38rpx;
	}
	.job-box .icon{width: 32rpx;height: 32rpx;}

	.job-box .btn-group {}

	.job-box .btn-group .btn {
		width: 136rpx;
		height: 56rpx;
		border-radius: 12rpx;
	}

	.job-box .btn-group .btn+.btn {
		margin-left: 18rpx;
	}
	.job-box .btn-group .btn-bg{background-color: var(--backgroundDivisionColor);color:var(--contentFontFourColor)}
	.job-box .btn-group .btn-border{border:1rpx solid var(--buttonOutlineOneColor);color:var(--buttonOutlineOneColor)}
	.bg-e{background: rgba(255,217,181,0.1);}
	.ft{margin-top: 54rpx;}
</style>